Syntax Snag need extra eyes

Syntax Snag need extra eyes

am 16.07.2009 18:17:07 von tmiller

I'm almost there with my little pagination script but now I'm hung on the
"Unexpected T_Variable" error...which in the past has been a semi-colon
missing so I'm not sure why this is throwing it...eyes please:

printf(' href=3D"view.php?name=3D$row['name']">%s
%s

',$row['n=
ame']
,$row['address']);


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Syntax Snag need extra eyes

am 16.07.2009 18:19:08 von Bob McConnell

From: Miller, Terion

> I'm almost there with my little pagination script but now I'm hung on
the
> "Unexpected T_Variable" error...which in the past has been a
semi-colon
> missing so I'm not sure why this is throwing it...eyes please:
>=20
> printf(' >
href=3D"view.php?name=3D$row['name']">%s
%s

',$row[=
'na
me']
> ,$row['address']);

It looks like you have nested single quotes. You probably need to escape
the inside set.

Bob McConnell

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Syntax Snag need extra eyes

am 16.07.2009 18:25:44 von List Manager

Miller, Terion wrote:
> I'm almost there with my little pagination script but now I'm hung on the
> "Unexpected T_Variable" error...which in the past has been a semi-colon
> missing so I'm not sure why this is throwing it...eyes please:
>
> printf(' > href="view.php?name=$row['name']">%s
%s

',$row['name']
> ,$row['address']);
>
>

The single ticks in your array() variable is causing the problem.

plus, since you are using single quotes for the entire string, the
variable isn't going to be interpreted as a variable. It will simply
print the string $row['name']

Also, this is the wrong way to use printf(). Please go read the manual
page for this function.

Try:

printf(
'',
$row['name'],
$row['name'],
$row['address']
);

This is the correct way to use printf()


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Syntax Snag need extra eyes (RESOLVED)

am 16.07.2009 18:28:57 von tmiller

Thanks Jim!! I did read the manual and don't get it, like why is printf use=
d and not echo...how do you decided which to use?



On 7/16/09 11:25 AM, "Jim Lucas" wrote:

printf(
'',
$row['name'],
$row['name'],
$row['address']
);


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Syntax Snag need extra eyes

am 16.07.2009 18:34:49 von Andrew Ballard

--000e0cd484921ae51c046ed5402e
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

On Thu, Jul 16, 2009 at 12:25 PM, Jim Lucas wrote:

> Miller, Terion wrote:
> > I'm almost there with my little pagination script but now I'm hung on the
> > "Unexpected T_Variable" error...which in the past has been a semi-colon
> > missing so I'm not sure why this is throwing it...eyes please:
> >
> > printf(' > >
> href="view.php?name=$row['name']">%s
%s

',$row['name']
> > ,$row['address']);
> >
> >
>
> The single ticks in your array() variable is causing the problem.
>
> plus, since you are using single quotes for the entire string, the
> variable isn't going to be interpreted as a variable. It will simply
> print the string $row['name']
>
> Also, this is the wrong way to use printf(). Please go read the manual
> page for this function.
>
> Try:
>
> printf(
> '',
> $row['name'],
> $row['name'],
> $row['address']
> );
>
> This is the correct way to use printf()
>
>
>
I like this, just because I don't need to repeat $row['name'] (but it is the
same thing):

printf(
'',
$row['name'],
$row['address']
);

Andrew

--000e0cd484921ae51c046ed5402e--

Re: Syntax Snag need extra eyes

am 16.07.2009 18:35:47 von List Manager

Andrew Ballard wrote:
> On Thu, Jul 16, 2009 at 12:25 PM, Jim Lucas wrote:
>
>> Miller, Terion wrote:
>>> I'm almost there with my little pagination script but now I'm hung on the
>>> "Unexpected T_Variable" error...which in the past has been a semi-colon
>>> missing so I'm not sure why this is throwing it...eyes please:
>>>
>>> printf(' >>>
>> href="view.php?name=$row['name']">%s
%s

',$row['name']
>>> ,$row['address']);
>>>
>>>
>> The single ticks in your array() variable is causing the problem.
>>
>> plus, since you are using single quotes for the entire string, the
>> variable isn't going to be interpreted as a variable. It will simply
>> print the string $row['name']
>>
>> Also, this is the wrong way to use printf(). Please go read the manual
>> page for this function.
>>
>> Try:
>>
>> printf(
>> '',
>> $row['name'],
>> $row['name'],
>> $row['address']
>> );
>>
>> This is the correct way to use printf()
>>
>>
>>
> I like this, just because I don't need to repeat $row['name'] (but it is the
> same thing):
>
> printf(
> '',
> $row['name'],
> $row['address']
> );
>
> Andrew
>


I was wondering if that was possible.

Thanks for the tip.

Jim Lucas


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Syntax Snag need extra eyes (RESOLVED)

am 16.07.2009 18:36:57 von List Manager

Miller, Terion wrote:
> Thanks Jim!! I did read the manual and don't get it, like why is printf used and not echo...how do you decided which to use?
>
>
>
> On 7/16/09 11:25 AM, "Jim Lucas" wrote:
>
> printf(
> '',
> $row['name'],
> $row['name'],
> $row['address']
> );
>

I would say personal preference is the main factor.

I use echo mostly. Some people like print() and some line printf() &
sprintf(). Probably depends mostly on where you learned to program.

Honestly, echo and print() use the same internal PHP construct. From
what I understand, one links to the other as an alias or something to
that affect. Also, the parenthesis are optional when using echo and print.

Back in the day, to be consistent, most people used printf() in C or
other similar programming languages.

Jim Lucas


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Syntax Snag need extra eyes

am 16.07.2009 18:43:44 von Andrew Ballard

On Thu, Jul 16, 2009 at 12:35 PM, Jim Lucas wrote:
>
> Andrew Ballard wrote:
> > On Thu, Jul 16, 2009 at 12:25 PM, Jim Lucas wrote:
[snip]
> >> Also, this is the wrong way to use printf().  Please go read the =
manual
> >> page for this function.
> >>
> >> Try:
> >>
> >> printf(
> >>        '%s r />%s

',
> >>        $row['name'],
> >>        $row['name'],
> >>        $row['address']
> >> );
> >>
> >> This is the correct way to use printf()
> >>
> >>
> >>
> > I like this, just because I don't need to repeat $row['name'] (but it i=
s the
> > same thing):
> >
> > printf(
> >        '%1$s >
%2$s

',
> >        $row['name'],
> >        $row['address']
> > );
> >
> > Andrew
> >
>
>
> I was wondering if that was possible.
>
> Thanks for the tip.
>
> Jim Lucas
>

That's what I like about this list. I wasn't totally sure it would
work myself, but I was pretty sure it would, and this was another one
of those posts that provided just enough prompting for me to actually
pop the code into Zend Studio where I could test it pretty quickly.
:-)

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Syntax Snag need extra eyes

am 16.07.2009 18:55:06 von Phpster

On Thu, Jul 16, 2009 at 12:43 PM, Andrew Ballard wrote:
> On Thu, Jul 16, 2009 at 12:35 PM, Jim Lucas wrote:
>>
>> Andrew Ballard wrote:
>> > On Thu, Jul 16, 2009 at 12:25 PM, Jim Lucas wrote:
> [snip]
>> >> Also, this is the wrong way to use printf(). =A0Please go read the ma=
nual
>> >> page for this function.
>> >>
>> >> Try:
>> >>
>> >> printf(
>> >> =A0 =A0 =A0 =A0'%s
%s
>
',
>> >> =A0 =A0 =A0 =A0$row['name'],
>> >> =A0 =A0 =A0 =A0$row['name'],
>> >> =A0 =A0 =A0 =A0$row['address']
>> >> );
>> >>
>> >> This is the correct way to use printf()
>> >>
>> >>
>> >>
>> > I like this, just because I don't need to repeat $row['name'] (but it =
is the
>> > same thing):
>> >
>> > printf(
>> > =A0 =A0 =A0 =A0'%1$s
%2$s=


',
>> > =A0 =A0 =A0 =A0$row['name'],
>> > =A0 =A0 =A0 =A0$row['address']
>> > );
>> >
>> > Andrew
>> >
>>
>>
>> I was wondering if that was possible.
>>
>> Thanks for the tip.
>>
>> Jim Lucas
>>
>
> That's what I like about this list. I wasn't totally sure it would
> work myself, but I was pretty sure it would, and this was another one
> of those posts that provided just enough prompting for me to actually
> pop the code into Zend Studio where I could test it pretty quickly.
> :-)
>
> Andrew
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

another option is to wrap the array elements in curly braces

printf(' href=3D"view.php?name=3D{$row['name']}">%s
%s

',$row[=
'name']
,$row['address']);

--=20

Bastien

Cat, the other other white meat

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Syntax Snag need extra eyes

am 16.07.2009 20:10:31 von List Manager

Bastien Koert wrote:
> On Thu, Jul 16, 2009 at 12:43 PM, Andrew Ballard wrote:
>> On Thu, Jul 16, 2009 at 12:35 PM, Jim Lucas wrote:
>>> Andrew Ballard wrote:
>>>> On Thu, Jul 16, 2009 at 12:25 PM, Jim Lucas wrote:
>> [snip]
>>>>> Also, this is the wrong way to use printf(). Please go read the manual
>>>>> page for this function.
>>>>>
>>>>> Try:
>>>>>
>>>>> printf(
>>>>> '',
>>>>> $row['name'],
>>>>> $row['name'],
>>>>> $row['address']
>>>>> );
>>>>>
>>>>> This is the correct way to use printf()
>>>>>
>>>>>
>>>>>
>>>> I like this, just because I don't need to repeat $row['name'] (but it is the
>>>> same thing):
>>>>
>>>> printf(
>>>> '',
>>>> $row['name'],
>>>> $row['address']
>>>> );
>>>>
>>>> Andrew
>>>>
>>>
>>> I was wondering if that was possible.
>>>
>>> Thanks for the tip.
>>>
>>> Jim Lucas
>>>
>> That's what I like about this list. I wasn't totally sure it would
>> work myself, but I was pretty sure it would, and this was another one
>> of those posts that provided just enough prompting for me to actually
>> pop the code into Zend Studio where I could test it pretty quickly.
>> :-)
>>
>> Andrew
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> another option is to wrap the array elements in curly braces
>
> printf(' > href="view.php?name={$row['name']}">%s
%s

',$row['name']
> ,$row['address']);
>

No, that won't work. The string that it is in, was created using single
quotes. Therefor the array reference will never be looked at. It will
simply print the actuall string, not the value associated to the array
reference.

Jim Lucas


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php